package com.example.yupao_project.component;

import com.example.yupao_project.utils.AppVar;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Component;

/**
 * 获取Session中的内容
 * @author: 杰
 * @date: 2024/5/1 13:45
 */
@Component
public class SessionUtil {
    public Object getSession(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        if (session == null || session.getAttribute(AppVar.SESSION_KEY_USERINFO) == null) {
            return null;
        }
        return session.getAttribute(AppVar.SESSION_KEY_USERINFO);
    }
}
